home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 2
/
Atari Mega Archive CD - Volume 2.iso
/
minix
/
up1510b.tgz
/
up1510b
/
src
/
commands
/
elvis
/
vi.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-15
|
19KB
|
677 lines
/* vi.c */
/* Author:
* Steve Kirkendall
* 16820 SW Tallac Way
* Beaverton, OR 97006
* kirkenda@jove.cs.pdx.edu, or ...uunet!tektronix!psueea!jove!kirkenda
*/
#include <ctype.h>
#include "vi.h"
/* This array describes what each key does */
#define NO_FUNC (MARK (*)())0
#define NO_ARGS 0
#define CURSOR_COUNT 1
#define CURSOR 2
#define CURSOR_CNT_KEY 3
#define CURSOR_MOVED 4
#define CURSOR_EOL 5
#define ZERO 6
#define DIGIT 7
#define CURSOR_TEXT 8
#define CURSOR_CNT_CMD 9
#define KEYWORD 10
#define NO_FLAGS 0x00
#define MVMT 0x01 /* this is a movement command */
#define PTMV 0x02 /* this can be *part* of a movement command */
#define FRNT 0x04 /* after move, go to front of line */
#define INCL 0x08 /* include last char when used with c/d/y */
#define LNMD 0x10 /* use line mode of c/d/y */
#define NCOL 0x20 /* this command can't change the column# */
#define NREL 0x40 /* this is "non-relative" -- set the '' mark */
#define SDOT 0x80 /* set the "dot" variables, for the "." cmd */
static struct keystru
{
MARK (*func)(); /* the function to run */
char args; /* description of the args needed */
char flags; /* other stuff */
}
vikeys[] =
{
/* NUL not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ^A not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ^B page backward */ {movescroll, CURSOR_CNT_CMD, FRNT},
/* ^C not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ^D scroll dn 1/2page*/ {movescroll, CURSOR_CNT_CMD, NCOL},
/* ^E scroll up */ {movescroll, CURSOR_CNT_CMD, NCOL},
/* ^F page forward */ {movescroll, CURSOR_CNT_CMD, FRNT},
/* ^G show file status */ {v_status, NO_ARGS, NO_FLAGS},
/* ^H move left, like h*/ {moveleft, CURSOR_COUNT, MVMT},
/* ^I not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ^J move down */ {movedown, CURSOR_COUNT, MVMT|LNMD},
/* ^K not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ^L redraw screen */ {v_redraw, NO_ARGS, NO_FLAGS},
/* ^M mv front next ln */ {movedown, CURSOR_COUNT, MVMT|FRNT|LNMD},
/* ^N move down */ {movedown, CURSOR_COUNT, MVMT|LNMD},
/* ^O not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ^P not defined */ {moveup, CURSOR_COUNT, MVMT|LNMD},
/* ^Q not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ^R redraw screen */ {v_redraw, NO_ARGS, NO_FLAGS},
/* ^S not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ^T not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ^U scroll up 1/2page*/ {movescroll, CURSOR_CNT_CMD, NCOL},
/* ^V not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ^W not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ^X not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ^Y scroll down */ {movescroll, CURSOR_CNT_CMD, NCOL},
/* ^Z not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ESC not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ^\ not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ^] keyword is tag */ {v_tag, KEYWORD, NO_FLAGS},
/* ^^ not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ^_ not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* SPC move right,like l*/ {moveright, CURSOR_COUNT, MVMT},
/* ! run thru filter */ {v_filter, CURSOR_MOVED, NO_FLAGS},
/* " select cut buffer*/ {v_selcut, CURSOR_CNT_KEY, PTMV},
#ifndef NO_EXTENSIONS
/* # increment number */ {v_increment, KEYWORD, SDOT},
#else
/* # not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
#endif
/* $ move to rear */ {moverear, CURSOR, MVMT|INCL},
/* % move to match */ {movematch, CURSOR, MVMT|INCL},
/* & not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ' move to a mark */ {movetomark, CURSOR_CNT_KEY, MVMT|FRNT|NREL|LNMD},
#ifndef NO_SENTENCE
/* ( mv back sentence */ {movebsentence, CURSOR_COUNT, MVMT},
/* ) mv fwd sentence */ {movefsentence, CURSOR_COUNT, MVMT},
#else
/* ( not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ) not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
#endif
/* * not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* + mv front next ln */ {movedown, CURSOR_COUNT, MVMT|FRNT|LNMD},
#ifndef NO_CHARSEARCH
/* , reverse [fFtT] cmd*/ {move_ch, CURSOR_CNT_CMD, MVMT|INCL},
#else
/* , not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
#endif
/* - mv front prev ln */ {moveup, CURSOR_COUNT, MVMT|FRNT|LNMD},
/* . special... */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* / forward search */ {movefsrch, CURSOR_TEXT, MVMT|NREL},
/* 0 part of count? */ {NO_FUNC, ZERO, MVMT|PTMV},
/* 1 part of count */ {NO_FUNC, DIGIT, PTMV},
/* 2 part of count */ {NO_FUNC, DIGIT, PTMV},
/* 3 part of count */ {NO_FUNC, DIGIT, PTMV},
/* 4 part of count */ {NO_FUNC, DIGIT, PTMV},
/* 5 part of count */ {NO_FUNC, DIGIT, PTMV},
/* 6 part of count */ {NO_FUNC, DIGIT, PTMV},
/* 7 part of count */ {NO_FUNC, DIGIT, PTMV},
/* 8 part of count */ {NO_FUNC, DIGIT, PTMV},
/* 9 part of count */ {NO_FUNC, DIGIT, PTMV},
/* : run single EX cmd*/ {v_1ex, CURSOR_TEXT, NO_FLAGS},
#ifndef NO_CHARSEARCH
/* ; repeat [fFtT] cmd*/ {move_ch, CURSOR_CNT_CMD, MVMT|INCL},
#else
/* ; not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
#endif
/* < shift text left */ {v_shiftl, CURSOR_MOVED, SDOT|FRNT},
/* = not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* > shift text right */ {v_shiftr, CURSOR_MOVED, SDOT|FRNT},
/* ? backward search */ {movebsrch, CURSOR_TEXT, MVMT|NREL},
/* @ not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* A append at EOL */ {v_insert, CURSOR_CNT_CMD, SDOT},
/* B move back Word */ {movebWord, CURSOR_COUNT, MVMT},
/* C change to EOL */ {v_change, CURSOR_EOL, SDOT},
/* D delete to EOL */ {v_delete, CURSOR_EOL, SDOT},
/* E move end of Word */ {moveeWord, CURSOR_COUNT, MVMT|INCL},
#ifndef NO_CHARSEARCH
/* F move bk to char */ {moveFch, CURSOR_CNT_KEY, MVMT|INCL},
#else
/* F not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
#endif
/* G move to line # */ {movetoline, CURSOR_COUNT, MVMT|NREL|LNMD},
/* H move to row */ {moverow, CURSOR_CNT_CMD, FRNT},
/* I insert at front */ {v_insert, CURSOR_CNT_CMD, SDOT},
/* J join lines */ {v_join, CURSOR_COUNT, SDOT},
#ifndef NO_EXTENSIONS
/* K look up keyword */ {v_keyword, KEYWORD, NO_FLAGS},
#else
/* K not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
#endif
/* L move to last row */ {moverow, CURSOR_CNT_CMD, FRNT},
/* M move to mid row */ {moverow, CURSOR_CNT_CMD, FRNT},
/* N reverse prev srch*/ {moveNsrch, CURSOR, MVMT},
/* O insert above line*/ {v_insert, CURSOR_CNT_CMD, SDOT},
/* P paste before */ {v_paste, CURSOR_CNT_CMD, NO_FLAGS},
/* Q quit to EX mode */ {v_quit, NO_ARGS, NO_FLAGS},
/* R overtype */ {v_overtype, CURSOR, SDOT},
/* S change line */ {v_change, CURSOR_MOVED, SDOT},
#ifndef NO_CHARSEARCH
/* T move bk to char */ {moveTch, CURSOR_CNT_KEY, MVMT|INCL},
#else
/* T not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
#endif
/* U undo whole line */ {v_undoline, CURSOR, FRNT},
/* V not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* W move forward Word*/ {movefWord, CURSOR_COUNT, MVMT},
/* X delete to left */ {v_Xchar, CURSOR_COUNT, SDOT},
/* Y yank text */ {v_yank, CURSOR_MOVED, NO_FLAGS},
/* Z save file & exit */ {v_xit, CURSOR_CNT_KEY, NO_FLAGS},
/* [ move back section*/ {movebsection, CURSOR_CNT_KEY, MVMT|LNMD|NREL},
/* \ not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ] move fwd section */ {movefsection, CURSOR_CNT_KEY, MVMT|LNMD|NREL},
/* ^ move to front */ {movefront, CURSOR, MVMT},
/* _ not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* ` move to mark */ {movetomark, CURSOR_CNT_KEY, MVMT|NREL},
/* a append at cursor */ {v_insert, CURSOR_CNT_CMD, SDOT},
/* b move back word */ {movebword, CURSOR_COUNT, MVMT},
/* c change text */ {v_change, CURSOR_MOVED, SDOT},
/* d delete op */ {v_delete, CURSOR_MOVED, SDOT},
/* e move end word */ {moveeword, CURSOR_COUNT, MVMT|INCL},
#ifndef NO_CHARSEARCH
/* f move fwd for char*/ {movefch, CURSOR_CNT_KEY, MVMT|INCL},
#else
/* f not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
#endif
/* g not defined */ {NO_FUNC, NO_ARGS, NO_FLAGS},
/* h move left */ {moveleft, CURSOR_COUNT, MVMT},
/* i insert at cursor */ {v_insert, CURSOR_CNT_CMD, SDOT},
/* j move down */ {movedown, CURSOR_COUNT, MVMT|NCOL|LNMD},
/* k move up */ {moveup, CURSOR_COUNT, MVMT|NCOL|LNMD},
/* l move right */ {moveright, CURSOR_COUNT, MVMT},
/* m define a mark */ {v_mark, CURSOR_CNT_KEY